import scrapy
from scrapy import Request
from scrapy_splash import SplashRequest

from jayce.items import WuditianxiaItem


class WuditianxiaSpider(scrapy.Spider):
    name = 'wuditianxia'
    allowed_domains = ['www.5ilrc.com']
    start_urls = ['https://www.5ilrc.com/yuedu/119/1371335.html']

    def start_requests(self):
        for url in self.start_urls:
            yield Request(url=url)

    def parse(self, response):
        title = response.xpath("//div[@class='bookname']/h1/text()").extract()[0]
        title_number = title.strip().split(" ")[0]
        title_name = title.strip().split(" ")[1]
        title_content = [line.extract() for line in response.xpath("//div[@id='content']/p/text()")]

        yield WuditianxiaItem(title_name=title_name, title_number=title_number, title_content=title_content)
